<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="common :: header"/>
<body>
<div class="page">
    <div class="card">
        <div class="card-header">
            <form id="search_form">
                <input class="easyui-textbox" data-options="label:'标题'" name="noticeTitle" style="width:180px;">
                <input id="search_type" name="noticeType" style="width:190px;">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="dm.resetForm('search_form');">重置</a>
                <a href="#" class="easyui-linkbutton button-info" data-options="iconCls:'icon-search'" onclick="dm.search('table', 'search_form')">查询</a>
            </form>
        </div>
        <div class="card-body">
            <div id="table"></div>
            <div id="toolbar" style="display: none">
                <a shiro:hasPermission="system:notice:add" href="#" onclick="add()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-add',plain:true">增加</a>
                <a shiro:hasPermission="system:notice:edit" href="#" onclick="edit()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-edit',plain:true">修改</a>
                <a shiro:hasPermission="system:notice:delete" href="#" onclick="remove()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-remove',plain:true">删除</a>
            </div>
        </div>
    </div>
</div>
<script th:inline="javascript">
    var types = [[${@dict.getType('sys_notice_type')}]];
    var datas = [[${@dict.getType('sys_notice_status')}]];

    $(function() {
        $('#search_type').combobox({
            label: "类型",
            url: '/system/dict/getDictData?type=sys_notice_type',
            panelHeight: 'auto',
            editable: false
        });

        $('#table').datagrid({
            url: '/system/notice/list',
            fit: true,
            fitColumns: true,
            nowrap: true,
            singleSelect: true,
            pagination: true,
            pageSize: 20, // 每一页多少条数据
            pageList: [ 10, 20, 30, 40, 50 ], // 可以选择的每页的大小的combobox
            idField: 'noticeId',
            sortName: 'noticeId',
            toolbar: '#toolbar',
            columns:[ [
                {field: 'ck', checkbox: true },
                {field: 'noticeTitle', title: '标题', align:'center',width: 260},
                {field: 'noticeType', title: '类型', align:'center',width: 80, formatter: function (value) {
                    return dictFormatter(types, value);
                }},
                {field: 'status', title: '状态', align:'center',width: 60, formatter: function (value) {
                    return dictFormatter(datas, value);
                }},
                {field: 'createBy',title: '创建者',align:'center',sortable: true, width: 100},
                {field: 'createTime',title: '创建时间',align:'center',sortable: true, width: 140,formatter: timeFormatter}
            ] ]
        });
    });

    function add() {
        dm.openDialog('新增公告', '/system/notice/add', '', '');
    }
    function edit() {
        dm.getRow('table',row => {
            dm.openDialog('修改公告','/system/notice/edit/'+row.noticeId, '', '');
        })
    }

    function remove() {
        dm.getRow('table', function(row) {
            dm.confirm('确定要删除该通知公告吗？', function () {
                dm.post('/system/notice/delete/' + row.noticeId, {}, function () {
                    dm.search('table');
                })
            })
        })
    }

</script>
</body>
</html>
